home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 January: Mac OS SDK / Dev.CD Jan 98 SDK1.toast / Development Kits (Disc 1) / QuickDraw 3D / Samples / SampleCode / BoxMooV / sources / BoxMooV_window.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-14  |  3.2 KB  |  138 lines  |  [TEXT/CWIE]

  1. /*  window.c                                                                            
  2.  
  3.     Rick Evans - Sept. 1996    derived from BoxPaint_window.c
  4.     Michael Bishop - August 21 1996                                                    
  5.     Nick Thompson
  6.     (c)1994-96 Apple computer Inc., All Rights Reserved                                
  7.  
  8. */
  9.  
  10. #include <Devices.h>
  11.  
  12. #include    "BoxMooV_window.h"
  13. #include    "BoxMooV_document.h"
  14.  
  15. /* -------------------------------------------------------------------------------------------
  16. ** Window_New
  17. ** Kind of a dummy function at the moment.
  18. */
  19. WindowPtr Window_New(void)
  20. {
  21.     WindowPtr    tempWindow = GetNewCWindow( kWindowResID, NULL, (WindowPtr)-1L );
  22.     
  23.     return tempWindow ;
  24. }
  25.  
  26.  
  27. /* -------------------------------------------------------------------------------------------
  28. ** Window_Delete
  29. ** Call this function when we are done with a window, deallocate any storage allocated for this,
  30. ** this gets called when we close a document.
  31. */
  32.  
  33. void Window_Delete(WindowPtr theWindow)
  34. {
  35.  
  36.     if( theWindow != NULL )
  37.     {
  38.         DisposeWindow ( theWindow ) ;
  39.     }
  40.     
  41. }
  42.  
  43. /* -------------------------------------------------------------------------------------------
  44. ** Window_Update
  45. ** 
  46. */
  47. void Window_Update( WindowPtr theWindow )
  48. {
  49.  
  50.     CGrafPtr            savedPort ;
  51.     
  52.     if( theWindow != NULL ) 
  53.     {
  54.         DocumentHdl        myDocumentHandle = Document_GetFromWindow(theWindow);
  55.         Rect            updateRect = (**(theWindow->visRgn)).rgnBBox;
  56.         
  57.         if( myDocumentHandle != NULL )
  58.         {
  59.             GetPort((GrafPtr *) &savedPort );
  60.             SetPort( theWindow ) ;
  61.             
  62.             BeginUpdate( theWindow );
  63.             
  64.             HLock( (Handle)myDocumentHandle  ) ;
  65.             Document_Draw(*myDocumentHandle ) ;
  66.             HUnlock( (Handle)myDocumentHandle  ) ;
  67.             
  68.             EndUpdate( theWindow );
  69.             SetPort( (GrafPtr )savedPort ) ;
  70.         }
  71.     }
  72. }
  73.  
  74.  
  75. /* ---------------------------------------------------------------------------------- 
  76. **     Window_Activate
  77. **    is called when an theEvent is received that reports that
  78. **     a theWindow is being either activated or deactivated. 
  79. */
  80. void Window_Activate(WindowPtr theWindow, short activate)
  81. {
  82.     if (theWindow) {
  83.         if (activate) {
  84.         
  85.             /*  do whatever else you'd like to do for a activate theEvent */
  86.             /* LoadScrap() ;
  87.             */
  88.         } else {
  89.         
  90.             /*  do whatever you'd like to do for a deactivate theEvent */
  91.             /*UnloadScrap() ;
  92.             */
  93.         }
  94.     }
  95. }
  96.  
  97. void Window_DoContent (WindowPtr theWindow, EventRecord *event)
  98. {
  99. #if defined(__MWERKS__)
  100. #pragma unused ( event )
  101. #endif
  102.     CGrafPtr    oldPort;
  103.     DocumentHdl    theDocument = Document_GetFromWindow(theWindow);
  104.     
  105.     GetPort((GrafPtr *)&oldPort);
  106.     SetPort(theWindow);
  107.  
  108.     SetPort((GrafPtr)oldPort);
  109. }
  110.  
  111.  
  112. /* ---------------------------------------------------------------------------------- 
  113. **     Window_GetNextWindow
  114. **    Returns the next in the queue
  115. */
  116. WindowPtr Window_GetNextWindow(WindowPtr theWindow)
  117. {
  118.     if (theWindow != NULL)
  119.         return (WindowPtr)((WindowPeek)theWindow)->nextWindow;
  120.     else return NULL;
  121. }
  122.  
  123. /* ---------------------------------------------------------------------------------- 
  124. **     Window_DestroyAll destroys all the windows in the app
  125. **     
  126. */
  127. void Window_DestroyAll(void)
  128. {
  129.     WindowPtr theWindow;
  130.     
  131.     theWindow = FrontWindow();                        /*    Start with the active window    */
  132.     
  133.     while (theWindow != NULL)
  134.     {
  135.         Document_Delete( Document_GetFromWindow(theWindow) ) ;    /*    delete it    */
  136.         theWindow = Window_GetNextWindow(theWindow);            /*    go down the list    */
  137.     }
  138. }